home *** CD-ROM | disk | FTP | other *** search
/ MacHack 2000 / MacHack 2000.toast / pc / The Hacks / Softshoe / Lisa's Portable Parts / Arrays / ArrayOf.h < prev    next >
Encoding:
Text File  |  2000-06-23  |  2.4 KB  |  76 lines

  1. // ArrayOf.h
  2.  
  3. #ifndef ArrayOf_h
  4. #define ArrayOf_h
  5.  
  6. #ifndef Integers_h
  7. #include "Integers.h"
  8. #endif
  9. #ifndef DebugMessage_h
  10. #include "DebugMessage.h"
  11. #endif
  12. #ifndef Assert_h
  13. #include "Assert.h"
  14. #endif
  15. #ifndef Range_h
  16. #include "Range.h"
  17. #endif
  18. #ifndef ConstArrayOf_h
  19. #include "ConstArrayOf.h"
  20. #endif
  21.  
  22. // The includes above have been flattened so that weak compilers
  23. // can cope better.
  24.  
  25. template < class Element >
  26. class ArrayOf: public ConstArrayOf< Element >
  27.   {
  28.     public:
  29.         typedef typename ArrayOf< Element > ArrayType;
  30.         typedef typename ConstArrayOf< Element > ConstArrayType;
  31.         typedef int32 (*Comparison)( const Element&, const Element& );
  32.  
  33.     private:
  34.         ArrayOf( ConstArrayType theArrayOf )
  35.           : ConstArrayOf< Element >( theArrayOf )
  36.           {}
  37.                 
  38.     public:
  39.         ArrayOf()        {}        
  40.         ArrayOf( Element *theStart, uint32 theLength )
  41.           : ConstArrayOf< Element >( theStart, theLength )
  42.           {}
  43.  
  44.         Element *Start() const                    { return const_cast<Element *>( this->ConstArrayType::Start() ); }
  45.         Element *End() const                        { return const_cast<Element *>( this->ConstArrayType::End() ); }
  46.         
  47.         Element& operator[]( uint32 i ) const
  48.             { return const_cast<Element &>( ConstArrayType::operator[]( i ) ); }
  49.         
  50.         const ArrayType Head( uint32 position ) const                { return this->ConstArrayType::Head( position ); }
  51.         const ArrayType Tail( uint32 position ) const                { return this->ConstArrayType::Tail( position ); }
  52.         const ArrayType Middle( URange32 range ) const                { return this->ConstArrayType::Middle( range ); }
  53.  
  54.         void Append( ArrayType tail )                                        { this->ConstArrayType::Append( tail ); }
  55.         void Prepend( ArrayType head )                                    { this->ConstArrayType::Prepend( head ); }
  56.         
  57.         void operator+=( ArrayType tail )                                { this->ConstArrayType::Append( tail ); }
  58.         const ArrayType operator+( ArrayType tail )                    { return this->ConstArrayType::operator+( tail ); }
  59.  
  60.         const ArrayType operator&( ConstArrayType r ) const        { return this->ConstArrayType::operator&( r ); }
  61.         void operator|=( ArrayType r )                                    { this->ConstArrayType::operator|=( r ); }
  62.         const ArrayType operator|( ArrayType r ) const                { return this->ConstArrayType::operator|( r ); }
  63.         const ConstArrayType operator|( ConstArrayType r ) const    { return this->ConstArrayType::operator|( r ); }
  64.         
  65.         uint32 operator<<( ConstArrayType r ) const;        // returns the amount copied
  66.         uint32 BitwiseCopy( ConstArrayType r ) const;
  67.         
  68.         void SortBy( Comparison ) const;
  69.   };
  70.  
  71. #ifndef ArrayOf_cp
  72. #include "ArrayOf.cp"
  73. #endif
  74.  
  75. #endif
  76.